package client;

import java.net.SocketException;
import java.util.concurrent.LinkedBlockingQueue;
import communication.Message;
import communication.client.ServerHandle;
import exception.ParseException;

public class MessageReciever implements Runnable {
	LinkedBlockingQueue<Message> messageQueue;
	ServerHandle serverHandle;

	public MessageReciever(ServerHandle serverHandle,
			LinkedBlockingQueue<Message> messageQueue) {
		this.messageQueue = messageQueue;
		this.serverHandle = serverHandle;
	}
	@Override
	public void run() {

		while (true) {
			try {
				Message msg = serverHandle.receiveMessage();

				messageQueue.add(msg);
				if (msg.getType().toString().equalsIgnoreCase("serverShutdown")) {
					System.out.println(msg.getType().toString());
					break;
				}

			} catch (ParseException e) {
				e.printStackTrace();
			} catch (SocketException e) {
				e.printStackTrace();
			}
		}
	}
}
